<?php
/**
 * Created by PhpStorm.
 * User: lijie
 * Date: 2018/10/31
 * Time: 16:10
 */
namespace app\reserve\model;

use think\Model;
use think\Db;

class Onecard extends Model{

    protected $table = "orange_onecard";
    protected $autoWriteTimestamp = true;
    protected $createTime = "ctime";
    protected $updateTime = "utime";
    protected $dateFormat;
    protected function getCtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    protected function getUtimeAttr($vlue){
        return date("Y-m-d H:i:s",$vlue);
    }
    /**
     * Notes:  添加一卡通
     * Create Date: 2018/10/31
     * Create by :lijie
     */
    public function addOne($param)
    {
        return $this->isUpdate(false)->save($param);
    }

    /**
     * Notes:  一卡通列表
     * Create Date: 2018/10/31
     * Create by :lijie
     */
    public function selectOne($where,$pagenum,$listNum)
    {
        return $this
            ->where($where)
            ->alias("o")
            ->field("o.id,o.cardnumber,o.wallet,o.ctime,o.utime,o.status,u.nickName")
            ->join("__USER__ u",    'o.u_id = u.u_id',  'LEFT')
            ->order("o.ctime desc")->page($pagenum,$listNum)->select();
    }

    /**
     * Notes:  一卡通详情
     * Create Date: 2018/10/31
     * Create by :lijie
     */
    public function findOne($where)
    {
        return $this->where($where)->find();
    }
}